#!/bin/bash
#
# Example shared file server restore script
#         This example uses the archive created by bck script to restore 
#         the shared file server.
#   
#   MYLOGPATH should be subsituted with the correct path
#

do_logdoesnotexist()
{
   echo "$LOGPATH\log.dat file does not exist."
   exit 1
}

do_cpfilesfailed()
{
   echo "Error restoring backup files. rst aborted."
   exit 2
}

do_dbrestorfailed()
{
   echo "DBRESTOR error or aborted processing. rst aborted."
   exit 3
}

# Unload the Shared File Server
ehcfree shfile## 

[ -f MYLOGPATH/log.dat ]
if [ $? -ne 0 ] ; then
   do_logdoesnotexist
fi

# Unarchive the tar file from /dev/fd0.  Must run this from
# from the root directory '/'.
currwd=$PWD
cd /

# Extract all files stored in the archive held on /dev/fd0
tar xMvf /dev/fd0
if [ $? -ne 0 ] ; then
   do_cpfilesfailed
fi

# Reset current working directory
cd $currwd

# Run dbrestor
dbrestor
if [ $? -ne 0 ] ; then
   do_restorfailed 
fi
rm MYLOGPATH/log.old

# All done
echo "DBRESTOR check completed. DB will be restored at next SHFILE## loading time."
